﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smarly.Bussines.Model.Subscription;
using Smarly.Web.Controllers.Base;
using Smarly.Web.Helpers;

namespace Smarly.Web.Controllers
{
	public class SubscriberController : BaseController
	{
		[HttpPost]
		public ActionResult Index(Subscriber model)
		{
			var uri = new Uri(Request.FullDomain() + Url.Action("Unsubscribe", "Subscriber", new { Email = "SUBSCRIBEREMAIL", ActivationCode = "ACTIVATIONCODE" }));

			model.Post(uri.ToString());
			if (ModelState.IsValid)
			{
				return Json(new { title = "Поздравляем!",  message = "Теперь вы будете в курсе свежих новостей", error = (string)null });
			}

			return JsonValidationErrors();
		}

		public ActionResult Unsubscribe(Subscriber model)
		{
			model.Delete();
			return RedirectToAction("Index", "Home");
		}

	}
}
